<?php
class editAction extends rareAction{
	public function execute(){
		$id = $this->getGetParam('id',0);
		if($id == 0) forward('product/index');
		$productDao = new DaoProduct();
		$product = $productDao->getOne(" id = '$id'");
		
		$imgDao = new DaoImage();
		$images = $imgDao->getList("typeID='".service_type::PRODUCT."' and itemID='$id'");	

		$this->assign('product',$product);
		$this->assign('images',$images);
	}
	public function executePost(){
		$product = $this->getPostParam('p',array());
		$id = $this->getPostParam('id',0);
		$images = $this->getPostParam('img',array());
		if(empty($product) || $id==0) jsonReturn(0,'修改失败');
		$productDao = new DaoProduct();
		
		$now = date("Y-m-d H:i:s");
		$product['updateTime'] = $now;
		$productDao->update(" id = '$id'",$product);
		if(!empty($images)){
			service_image::insert($images,service_type::PRODUCT,$id);
		}
		jsonReturn(1,'ok');
	}
}
?>
